HAL CRC migration: List of applicable concepts

This section provides information about the HAL CRC applicable architecture concepts.

Concepts for CRC

Concept

Description

Separation of initialization and configuration functions

The initialization has been split into two levels of functions:

  • HAL_CRC_Init: initialize the CRC and link it to a CRC instance.

  • HAL_CRC_SetConfig: configure the CRC according to the user parameters.

Removal and conversion of init structure to configuration structure

The init structure has been removed and moved into HAL_CRC_SetConfig function.

Renaming of the handle structure

The handle structure has been renamed to hal_crc_handle_t.

Renaming unitary init structures

The structure CRC_InitTypeDef is no longer available they are replaced with hal_crc_config_t.

Remove MspInit and MspDeInit callbacks

hal_crc_MspInit and hal_crc_MspDeInit are no longer available and have been replaced by a user sequence to initializes and configures the CRC.

Unitary configuration APIs

New APIs are available to get and set CRC features.

Introduction of HAL user data set/get APIs

Two functions to set and get user data are available: HAL_CRC_SetIndependentData and HAL_CRC_GetIndependentData.

Removal of hardware-related macros in HAL2

All hardware macros have been removed from the HAL CRC driver, and equivalent services are ensured through the LL APIs.

Revised and optimized HAL state machine

The CRC now is managed by three states:

  • HAL_CRC_STATE_RESET

  • HAL_CRC_STATE_IDLE

  • HAL_CRC_STATE_ACTIVE

Revised and optimized HAL API status returns

The HAL CRC functions were updated to return:

  • HAL_INVALID_PARAM: in case of a NULL p_config structure pointer.

  • HAL_TIMEOUT: in case of a user timeout.

  • HAL_OK: in case of a successfully completed operation.

Revised and optimized HAL error management

The HAL error handling mechanisms have been redesigned to improve the detection, reporting, and handling of errors. This provides more detailed and consistent error information.

Replaced TypeDef suffix with _t in type names

All TypeDef parts of the HAL CRC driver have been removed and replaced by _t.

Replaced nonmodifiable pointers with const keywords

Const keywords have been added to non-modifiable pointers to ensure that either the pointer itself or the data it points to cannot be modified. This enhances code safety and readability, prevents unintended modifications, and renders code more robust and maintainable.

Assertion implementation and usage in HAL1

The parameters and state are checked using ASSERT_DBG_STATE and ASSERT_DBG_PARAM macros.

Merge HAL extension files with common ones and remove the EX prefix from APIs.

Only one HAL CRC header file remains and all macros, define statements, and functions from hal_crc_ex.h have been moved to hal_crc.h.

Provide RTOS-compatible acquire/release bus services for communication peripheral drivers.

Lock management mechanisms have been removed from the HAL CRC layer.

Replace Finite Parameter Defines (Including PPP Instances) with Enum Types at HAL Levels.

Finite parameters (including CRC instances) have been converted into enumerated types (enums) at HAL level. This improves code readability, maintainability, and type safety.

Other HAL CRC changes

Concept

Consideration

Rework of the configuration structure: Renaming parameters

  • The Polynomial is defined by polynomial size and polynomial coefficient.

  • Keep the same naming through all the driver like Reversibility, CRC Initial value.

  • Remove default_polynomial_use and default_crc_init_value_use and provide HAL_CRC_ResetConfig API that applies the default CRC polynomial and init value.

Introduce the HAL_CRC_ResetConfig function to restore the CRC configuration to its default settings

Provide HAL_CRC_ResetConfig API that applies the default CRC parameters.

Rework of calculate and accumulate functions.

New CRC optimized calculation method for performance and footprint: - The user should only provide a pointer to void buffer ( no more input data format is used) and the buffer size should be the number of bytes - The user does not need to preprocess his data buffer depending on the data format. - The main idea of this method is to read from the input buffer with a step of 4 bytes using the 32bits pointer alignment concept. This method includes 3 steps:

Step1:Read the first non-aligned 32 bits buffer address (if they exist) from the input buffer and feed its data into DR register. This operation stops when the incremented address becomes 32 bits aligned

Step2: Read aligned 32 bits buffer address with a 32bits step and feed its data into DR register.

Step3: Read the last bytes if buffer length is not multiple of 4.